package com.vinjune.bigdata.bloomfilter.redis;

import com.vinjune.bigdata.bloomfilter.BloomFilterRedis;

/**
 * Created by 000376 on 2018/3/7.
 */
public class FilterBuilder {
    private String name;
    private int expectedElements;
    private double falsePositiveProbability;
    private BloomRedisService redis;

    public FilterBuilder(int expectedElements, double falsePositiveProbability) {
        this.expectedElements(expectedElements).falsePositiveProbability(falsePositiveProbability);
    }

    public FilterBuilder expectedElements(int expectedElements) {
        this.expectedElements = expectedElements;
        return this;
    }

    public FilterBuilder falsePositiveProbability(double falsePositiveProbability) {
        this.falsePositiveProbability = falsePositiveProbability;
        return this;
    }

    public FilterBuilder name(String name) {
        this.name = name;
        return this;
    }

    public FilterBuilder redisService(BloomRedisService redis) {
        this.redis = redis;
        return this;
    }

    /** @deprecated */
    public BloomFilterRedis buildBloomFilter() {
        return new DefaultBloomFilterRedis(this.name, this.expectedElements, this.falsePositiveProbability, this.redis);
    }

    public BloomFilterRedis buildSimpleBloomFilter() {
        return new SimpleBloomFilterRedis(this.expectedElements, this.falsePositiveProbability, this.redis);
    }
}
